<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\controller\My;
use app\common\controller\MyHelp;
use think\Db;

/**
 * 示例接口
 */
class Demo extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 测试方法
     *
     * @ApiTitle    (测试名称)
     * @ApiSummary  (测试描述信息)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/demo/test/id/{id}/name/{name})
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="integer", required=true, description="会员ID")
     * @ApiParams   (name="name", type="string", required=true, description="用户名")
     * @ApiParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function test()
    {
        $admin =  db::table('fa_admin')->where('id', 1003)->find();
        $e =  MyHelp::getPrice($admin, 188, 200);
        //比如200面值 付款184 成本182 站长利润1 原利润 184-1-182-0.4=0.6元
        //到账100 退100 
        return json($e);
        $lirun = ($charge_amount / $order['mz']) * ($order['price'] - $order['cb'] - $order['mz'] / 200) - $order['sxf'];
        return $lirun;

        return json(Wechat::getAuthorizer('wx408c5a916e0e03e8'));
        $list = db::table('fa_ua_weishibie')->where('sss', 0)->limit(50)->select();
        foreach ($list as $key => $value) {
            $o = db::table('fa_ua_model')->where('model', $value['model'])->find();
            if ($o) {
                db::table('fa_ua_weishibie')->where('id', $value['id'])->delete();
            } else {
                db::table('fa_ua_weishibie')->where('id', $value['id'])->update(['sss' => 1]);
            }
        }
        return '666';
        return json(my::getPhonetype('Mozilla/5.0 (Linux; U; Android 9; zh-cn; PBBT00 Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/90.0.4430.61 Mobile Safari/537.36 HeyTapBrowser/10.8.20.2'));
        //Mozilla/5.0 (Linux; Android 11; Build/RKQ1.201217.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.99 XWEB/4434 MMWEBSDK/20230504 Mobile Safari/537.36 MMWEBID/7285 MicroMessenger/8.0.37.2380(0x28002536) WeChat/arm32 Weixin NetType/4G Language/zh_CN ABI/arm64
        $this->success('返回成功', $this->request->param());
    }
    public  function gfgfgfgfg()
    {
        $dateTime = gmdate("D, d M Y H:i:s T");
        $SecretId = 'AKID8q0EttKwsIx8udeXmlfIg3fn926i4yZ9z1rl'; # 密钥对的 SecretId
        $SecretKey = '2ki5MRIx4s22HG10D2eZj2OCAEZv24IzGJmB3X87'; # 密钥对的 SecretKey
        $srcStr = "date: " . $dateTime . "\n" . "source: " . "xxxxxx"; # 签名水印值，可填写任意值
        $Authen = 'hmac id="' . $SecretId . '", algorithm="hmac-sha1", headers="date source", signature="';
        $signStr = base64_encode(hash_hmac('sha1', $srcStr, $SecretKey, true));
        # echo $signStr;
        $Authen = $Authen . $signStr . "\"";
        //  echo $Authen;
        # echo '</br>';

        $ua = urlencode('Mozilla/5.0 (Linux; Android 12; LIO-AN00 Build/HUAWEILIO-AN00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/111.0.5563.116 Mobile Safari/537.36 XWEB/1110005 MMWEBSDK/20231002 MMWEBID/4779 MicroMessenger/8.0.43.2480(0x28002B3A) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64');
        $url = 'https://service-6tmho00c-1322497728.gz.apigw.tencentcs.com/release/getPhonetype?ua=' . $ua; # 用户 API 的访问路径
        $headers = array(
            'Host:service-6tmho00c-1322497728.gz.apigw.tencentcs.com', # 用户 API 所在服务的域名
            'Accept:text/html, */*; q=0.01',
            'Source: xxxxxx',
            'Date: ' . $dateTime,
            'Authorization: ' . $Authen,
            'X-Requested-With: XMLHttpRequest',
            # 'Accept-Encoding: gzip, deflate, sdch',


            # 如果是微服务 API，Header 中需要添加'X-NameSpace-Code'、'X-MicroService-Name'两个字段，通用 API 不需要添加。
            // 'X-NameSpace-Code: testmic',
            // 'X-MicroService-Name: provider-demo'
        );
        //  return json($headers);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");


        $data = curl_exec($ch);


        if (curl_errno($ch)) {
            print "Error: " . curl_error($ch);
        } else {
            # Show me the result 
            var_dump($data);
            curl_close($ch);
        }
    }
    /**
     * 无需登录的接口
     *
     */
    public function test1()
    {
        $this->success('返回成功', ['action' => 'test1']);
    }

    /**
     * 需要登录的接口
     *
     */
    public function test2()
    {
        $this->success('返回成功', ['action' => 'test2']);
    }

    /**
     * 需要登录且需要验证有相应组的权限
     *
     */
    public function test3()
    {
        $this->success('返回成功', ['action' => 'test3']);
    }
}
